/**
 * Project Name:springBoot_job
 * File Name:CityJobService.java
 * Package Name:com.libra.job
 * Date:2018年6月7日下午5:25:10
 * Copyright (c) 2018, wangzhicheng All Rights Reserved.
 *
*/

package com.libra.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.libra.bean.City;
import com.libra.dao.CityMapper;
import com.libra.utils.ErrorConstants;

/**
 * ClassName:CityJobService <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason:	 TODO ADD REASON. <br/>
 * Date:     2018年6月7日 下午5:25:10 <br/>
 * @author   wangzhicheng
 * @version  
 * @since    JDK 1.7
 * @see 	 
 */
@EnableScheduling //通过@EnableScheduling注解开启对计划任务的支持
@Service
public class ScheduledTaskService {
	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

	@Autowired
	private CityMapper cityMapper;
//    @Scheduled(fixedRate = 6000) //通过@Scheduled声明该方法是计划任务，使用fixedRate属性每隔固定时间执行  (fixedRateString)
    @Scheduled(fixedDelay = 5000)//使用fixedDelay属性  执行完以后过60S执行下一次  (fixedDelayString)
    public void reportCurrentTime(){
    	System.out.println("分割线："+new Date());
    	System.out.println("开始时间："+new Date().getTime());
    	City list=cityMapper.selectByPrimaryKey(1);
//    	System.out.println(ErrorConstants.SUCCESS.getErrCode());
//    	System.out.println(ErrorConstants.SUCCESS.getErrMsg());
//		System.out.println("执行定时任务:"+list.getCity());
		System.out.println("结束时间："+new Date().getTime());
    }

    @Scheduled(cron = "0 07 20 ? * *" ) //使用cron属性可按照指定时间执行，本例指的是每天20点07分执行；
    public void fixTimeExecution(){
        System.out.println("在指定时间 "+dateFormat.format(new Date())+" 执行");
    }
}

